1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module soup.Address; 26 27 private import gio.Cancellable; 28 private import gio.SocketAddress; 29 private import gio.SocketConnectableIF; 30 private import gio.SocketConnectableT; 31 private import glib.ConstructionException; 32 private import glib.MainContext; 33 private import glib.Str; 34 private import glib.c.functions; 35 private import gobject.ObjectG; 36 private import soup.c.functions; 37 public import soup.c.types; 38 39 40 /** */ 41 public class Address : ObjectG, SocketConnectableIF 42 { 43 /** the main Gtk struct */ 44 protected SoupAddress* soupAddress; 45 46 /** Get the main Gtk struct */ 47 public SoupAddress* getAddressStruct(bool transferOwnership = false) 48 { 49 if (transferOwnership) 50 ownedRef = false; 51 return soupAddress; 52 } 53 54 /** the main Gtk struct as a void* */ 55 protected override void* getStruct() 56 { 57 return cast(void*)soupAddress; 58 } 59 60 /** 61 * Sets our main struct and passes it to the parent class. 62 */ 63 public this (SoupAddress* soupAddress, bool ownedRef = false) 64 { 65 this.soupAddress = soupAddress; 66 super(cast(GObject*)soupAddress, ownedRef); 67 } 68 69 // add the SocketConnectable capabilities 70 mixin SocketConnectableT!(SoupAddress); 71 72 73 /** */ 74 public static GType getType() 75 { 76 return soup_address_get_type(); 77 } 78 79 /** 80 * Creates a #SoupAddress from @name and @port. The #SoupAddress's IP 81 * address may not be available right away; the caller can call 82 * soup_address_resolve_async() or soup_address_resolve_sync() to 83 * force a DNS resolution. 84 * 85 * Params: 86 * name = a hostname or physical address 87 * port = a port number 88 * 89 * Returns: a #SoupAddress 90 * 91 * Throws: ConstructionException GTK+ fails to create the object. 92 */ 93 public this(string name, uint port) 94 { 95 auto __p = soup_address_new(Str.toStringz(name), port); 96 97 if(__p is null) 98 { 99 throw new ConstructionException("null returned by new"); 100 } 101 102 this(cast(SoupAddress*) __p, true); 103 } 104 105 /** 106 * Returns a #SoupAddress corresponding to the "any" address 107 * for @family (or %NULL if @family isn't supported), suitable for 108 * using as a listening #SoupSocket. 109 * 110 * Params: 111 * family = the address family 112 * port = the port number (usually %SOUP_ADDRESS_ANY_PORT) 113 * 114 * Returns: the new #SoupAddress 115 * 116 * Throws: ConstructionException GTK+ fails to create the object. 117 */ 118 public this(SoupAddressFamily family, uint port) 119 { 120 auto __p = soup_address_new_any(family, port); 121 122 if(__p is null) 123 { 124 throw new ConstructionException("null returned by new_any"); 125 } 126 127 this(cast(SoupAddress*) __p, true); 128 } 129 130 /** 131 * Returns a #SoupAddress equivalent to @sa (or %NULL if @sa's 132 * address family isn't supported) 133 * 134 * Params: 135 * sa = a pointer to a sockaddr 136 * len = size of @sa 137 * 138 * Returns: the new #SoupAddress 139 * 140 * Throws: ConstructionException GTK+ fails to create the object. 141 */ 142 public this(sockaddr* sa, int len) 143 { 144 auto __p = soup_address_new_from_sockaddr(sa, len); 145 146 if(__p is null) 147 { 148 throw new ConstructionException("null returned by new_from_sockaddr"); 149 } 150 151 this(cast(SoupAddress*) __p, true); 152 } 153 154 /** 155 * Tests if @addr1 and @addr2 have the same IP address. This method 156 * can be used with soup_address_hash_by_ip() to create a 157 * #GHashTable that hashes on IP address. 158 * 159 * This would be used to distinguish hosts in situations where 160 * different virtual hosts on the same IP address should be considered 161 * the same. Eg, if "www.example.com" and "www.example.net" have the 162 * same IP address, then a single connection can be used to talk 163 * to either of them. 164 * 165 * See also soup_address_equal_by_name(), which compares by name 166 * rather than by IP address. 167 * 168 * Params: 169 * addr2 = another #SoupAddress with a resolved 170 * IP address 171 * 172 * Returns: whether or not @addr1 and @addr2 have the same IP 173 * address. 174 * 175 * Since: 2.26 176 */ 177 public bool equalByIp(Address addr2) 178 { 179 return soup_address_equal_by_ip(soupAddress, (addr2 is null) ? null : addr2.getAddressStruct()) != 0; 180 } 181 182 /** 183 * Tests if @addr1 and @addr2 have the same "name". This method can be 184 * used with soup_address_hash_by_name() to create a #GHashTable that 185 * hashes on address "names". 186 * 187 * Comparing by name normally means comparing the addresses by their 188 * hostnames. But if the address was originally created using an IP 189 * address literal, then it will be compared by that instead. 190 * 191 * In particular, if "www.example.com" has the IP address 10.0.0.1, 192 * and @addr1 was created with the name "www.example.com" and @addr2 193 * was created with the name "10.0.0.1", then they will compare as 194 * unequal for purposes of soup_address_equal_by_name(). 195 * 196 * This would be used to distinguish hosts in situations where 197 * different virtual hosts on the same IP address should be considered 198 * different. Eg, for purposes of HTTP authentication or cookies, two 199 * hosts with the same IP address but different names are considered 200 * to be different hosts. 201 * 202 * See also soup_address_equal_by_ip(), which compares by IP address 203 * rather than by name. 204 * 205 * Params: 206 * addr2 = another #SoupAddress with a resolved 207 * name 208 * 209 * Returns: whether or not @addr1 and @addr2 have the same name 210 * 211 * Since: 2.26 212 */ 213 public bool equalByName(Address addr2) 214 { 215 return soup_address_equal_by_name(soupAddress, (addr2 is null) ? null : addr2.getAddressStruct()) != 0; 216 } 217 218 /** 219 * Creates a new #GSocketAddress corresponding to @addr (which is assumed 220 * to only have one socket address associated with it). 221 * 222 * Returns: a new #GSocketAddress 223 * 224 * Since: 2.32 225 */ 226 public SocketAddress getGsockaddr() 227 { 228 auto __p = soup_address_get_gsockaddr(soupAddress); 229 230 if(__p is null) 231 { 232 return null; 233 } 234 235 return ObjectG.getDObject!(SocketAddress)(cast(GSocketAddress*) __p, true); 236 } 237 238 /** 239 * Returns the hostname associated with @addr. 240 * 241 * This method is not thread-safe; if you call it while @addr is being 242 * resolved in another thread, it may return garbage. You can use 243 * soup_address_is_resolved() to safely test whether or not an address 244 * is resolved before fetching its name or address. 245 * 246 * Returns: the hostname, or %NULL if it is not known. 247 */ 248 public string getName() 249 { 250 return Str.toString(soup_address_get_name(soupAddress)); 251 } 252 253 /** 254 * Returns the physical address associated with @addr as a string. 255 * (Eg, "127.0.0.1"). If the address is not yet known, returns %NULL. 256 * 257 * This method is not thread-safe; if you call it while @addr is being 258 * resolved in another thread, it may return garbage. You can use 259 * soup_address_is_resolved() to safely test whether or not an address 260 * is resolved before fetching its name or address. 261 * 262 * Returns: the physical address, or %NULL 263 */ 264 public string getPhysical() 265 { 266 return Str.toString(soup_address_get_physical(soupAddress)); 267 } 268 269 /** 270 * Returns the port associated with @addr. 271 * 272 * Returns: the port 273 */ 274 public uint getPort() 275 { 276 return soup_address_get_port(soupAddress); 277 } 278 279 /** 280 * Returns the sockaddr associated with @addr, with its length in 281 * *@len. If the sockaddr is not yet known, returns %NULL. 282 * 283 * This method is not thread-safe; if you call it while @addr is being 284 * resolved in another thread, it may return garbage. You can use 285 * soup_address_is_resolved() to safely test whether or not an address 286 * is resolved before fetching its name or address. 287 * 288 * Params: 289 * len = return location for sockaddr length 290 * 291 * Returns: the sockaddr, or %NULL 292 */ 293 public sockaddr* getSockaddr(int* len) 294 { 295 return soup_address_get_sockaddr(soupAddress, len); 296 } 297 298 /** 299 * A hash function (for #GHashTable) that corresponds to 300 * soup_address_equal_by_ip(), qv 301 * 302 * Returns: the IP-based hash value for @addr. 303 * 304 * Since: 2.26 305 */ 306 public uint hashByIp() 307 { 308 return soup_address_hash_by_ip(soupAddress); 309 } 310 311 /** 312 * A hash function (for #GHashTable) that corresponds to 313 * soup_address_equal_by_name(), qv 314 * 315 * Returns: the named-based hash value for @addr. 316 * 317 * Since: 2.26 318 */ 319 public uint hashByName() 320 { 321 return soup_address_hash_by_name(soupAddress); 322 } 323 324 /** 325 * Tests if @addr has already been resolved. Unlike the other 326 * #SoupAddress "get" methods, this is safe to call when @addr might 327 * be being resolved in another thread. 328 * 329 * Returns: %TRUE if @addr has been resolved. 330 */ 331 public bool isResolved() 332 { 333 return soup_address_is_resolved(soupAddress) != 0; 334 } 335 336 /** 337 * Asynchronously resolves the missing half of @addr (its IP address 338 * if it was created with soup_address_new(), or its hostname if it 339 * was created with soup_address_new_from_sockaddr() or 340 * soup_address_new_any().) 341 * 342 * If @cancellable is non-%NULL, it can be used to cancel the 343 * resolution. @callback will still be invoked in this case, with a 344 * status of %SOUP_STATUS_CANCELLED. 345 * 346 * It is safe to call this more than once on a given address, from the 347 * same thread, with the same @async_context (and doing so will not 348 * result in redundant DNS queries being made). But it is not safe to 349 * call from multiple threads, or with different @async_contexts, or 350 * mixed with calls to soup_address_resolve_sync(). 351 * 352 * Params: 353 * asyncContext = the #GMainContext to call @callback from 354 * cancellable = a #GCancellable object, or %NULL 355 * callback = callback to call with the result 356 * userData = data for @callback 357 */ 358 public void resolveAsync(MainContext asyncContext, Cancellable cancellable, SoupAddressCallback callback, void* userData) 359 { 360 soup_address_resolve_async(soupAddress, (asyncContext is null) ? null : asyncContext.getMainContextStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 361 } 362 363 /** 364 * Synchronously resolves the missing half of @addr, as with 365 * soup_address_resolve_async(). 366 * 367 * If @cancellable is non-%NULL, it can be used to cancel the 368 * resolution. soup_address_resolve_sync() will then return a status 369 * of %SOUP_STATUS_CANCELLED. 370 * 371 * It is safe to call this more than once, even from different 372 * threads, but it is not safe to mix calls to 373 * soup_address_resolve_sync() with calls to 374 * soup_address_resolve_async() on the same address. 375 * 376 * Params: 377 * cancellable = a #GCancellable object, or %NULL 378 * 379 * Returns: %SOUP_STATUS_OK, %SOUP_STATUS_CANT_RESOLVE, or 380 * %SOUP_STATUS_CANCELLED. 381 */ 382 public uint resolveSync(Cancellable cancellable) 383 { 384 return soup_address_resolve_sync(soupAddress, (cancellable is null) ? null : cancellable.getCancellableStruct()); 385 } 386 }